%%%-------------------------------------------------------------------
%%% @author glendy
%%% @copyright (C) 2025, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 16. 9月 2025 8:34
%%%-------------------------------------------------------------------
-author("glendy").

%% Public types

-type reconnect_sleep() :: no_reconnect | integer().

-type option() :: {host, string()} | {port, integer()} | {database, string()} | {password, string()} | {reconnect_sleep, reconnect_sleep()}.
-type server_args() :: [option()].

-type return_value() :: undefined | binary() | [binary() | nonempty_list()].

-type pipeline() :: [iolist()].

-type channel() :: binary().

%% Continuation data is whatever data returned by any of the parse
%% functions. This is used to continue where we left off the next time
%% the user calls parse/2.
-type continuation_data() :: any().
-type parser_state() :: status_continue | bulk_continue | multibulk_continue.

%% Internal parser state. Is returned from parse/2 and must be
%% included on the next calls to parse/2.
-record(pdata, {
  data_type = undefined :: undefined | redis_str | redis_error | redis_int | redis_multiline | redis_list,
  is_finish = false,
  multiline_str_size = 0,
  str_val = <<>>,
  int_val = 0,
  list_size = 0,
  list_val = []
}).

-record(pstate, {
  state = undefined :: undefined | redis_str | redis_error | redis_int | redis_multiline | redis_list,
  rest_bin = <<>> :: binary(),
  pdata = #pdata{} :: #pdata{}
}).

-define(NL, "\r\n").

-define(RECV_TIMEOUT, 5000).
-define(SEND_TIMEOUT, 5000).

-define(SOCKET_MODE, binary).
-define(SOCKET_OPTS, [{active, false}, {packet, raw}, {send_timeout, ?SEND_TIMEOUT}]).

-define(REDIS_CMD_SELECT(DataBase), redis_encode:encode([<<"SELECT">>, Database])).
-define(REDIS_CMD_AUTH(Password), redis_encode:encode([<<"AUTH">>, Password])).
